--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_sto_prfcontrainte AS (SELECT * FROM &erp.STO_PRFCONTRAINTE WHERE 1=2);




DELETE FROM se_sto_prfcontrainte;

 INSERT INTO se_sto_prfcontrainte
 (SELECT id prfcontrainte_cod,
         0 enreg_id,
         libelle prfcontrainte_lib,
         NULL prfcontrainte_lib2,
         'N' enreg_s
    FROM uv_ptypergt) ;

 UPDATE se_sto_prfcontrainte tf SET enreg_id=(select enreg_id FROM &erp.STO_PRFCONTRAINTE f WHERE f.prfcontrainte_cod=tf.prfcontrainte_cod) ;
 UPDATE se_sto_prfcontrainte tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('prfcontrainte_cod','STO_PRFCONTRAINTE','O') ;

 commit;



select * from (
SELECT &outils.stragg(source) source,prfcontrainte_cod, enreg_id, prfcontrainte_lib, prfcontrainte_lib2, enreg_s
FROM (
  SELECT 'uv' source ,g.* FROM se_sto_prfcontrainte g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.sto_prfcontrainte g
  )
GROUP BY prfcontrainte_cod, enreg_id, prfcontrainte_lib, prfcontrainte_lib2, enreg_s
HAVING Count(1)!=2) r
ORDER BY prfcontrainte_cod ;